03. Setting up my_robot

Setting up my_robot

The first task in this project is to create the my_robot ROS package. Inside my_robot , you will store and launch an empty Gazebo world file. As you proceed with the project, you will model and store a robot, as well as replace the empty world file with the world you created in the Build My World project. For now, follow these steps to set up my_robot .

Note: Do not have more than one my_robot instance in the Gazebo world otherwise it would not be able to launch.

Create the my_robot Package

1- Create and initialize a catkin_ws

Feel free to skip if you already have a catkin_ws .

$ mkdir -p /home/workspace/catkin_ws/src
$ cd /home/workspace/catkin_ws/src
$ catkin_init_workspace

** 2- Navigate to the src directory of your catkin_ws and create the my_robot package**:

$ cd /home/workspace/catkin_ws/src/
$ catkin_create_pkg my_robot

3- Next, create a worlds directory and a launch directory, that will further define the structure of your package :

$ cd /home/workspace/catkin_ws/src/my_robot/
$ mkdir launch
$ mkdir worlds

Create and Store an Empty Gazebo World File

Inside the worlds directory, create and store an empty Gazebo world file. As a reminder, in Gazebo a world is a collection of models, such as your robot, together with a specific environment. You can also define several other physical properties specific to this world.

1- Create an empty Gazebo world

An empty world in Gazebo is a simple world, with no objects or models.

$ cd /home/workspace/catkin_ws/src/my_robot/worlds/
$ touch empty.world

2- Add the following to empty.world

<?xml version="1.0" ?>

<sdf version="1.4">

  <world name="default">

    <include>
      <uri>model://ground_plane</uri>
    </include>

    <!-- Light source -->
    <include>
      <uri>model://sun</uri>
    </include>

    <!-- World camera -->
    <gui fullscreen='0'>
      <camera name='world_camera'>
        <pose>4.927360 -4.376610 3.740080 0.000000 0.275643 2.356190</pose>
        <view_controller>orbit</view_controller>
      </camera>
    </gui>

  </world>
</sdf>

The .world file uses the XML file format to describe all the elements with respect to the Gazebo environment. The simple world that you are creating here has the following elements:

  • <sdf> : The base element which encapsulates the entire file structure and content.
  • <world> : The world element defines the world description and several properties pertaining to that world. In this example, you are adding a ground plane, a light source, and a camera to your world. Each model or property can have further elements that add detail. For example, the camera has a pose element which defines its position and orientation.
  • <include> : The include element, along with the <uri> element, provide a path to a particular model. In Gazebo there are several models that are available by default.

Create a Launch File

Launch files in ROS allow us to execute more than one node simultaneously, which helps avoid the potentially tedious task of defining and launching several nodes in separate shells or terminals.

1- Create the world.launch file

$ cd /home/workspace/catkin_ws/src/my_robot/launch/
$ touch world.launch

2- Add the following to world.launch

<?xml version="1.0" encoding="UTF-8"?>

<launch>

  <!-- World File -->
  <arg name="world_file" default="$(find my_robot)/worlds/empty.world"/>

  <!-- Launch Gazebo World -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="use_sim_time" value="true"/>
    <arg name="debug" value="false"/>
    <arg name="gui" value="true" />
    <arg name="world_name" value="$(arg world_file)"/>
  </include>

</launch>

As in the case of the .world file, the .launch files are also based on XML. The structure for the launch files has two parts -

  • First, define arguments using the <arg> element. Each such element will have a name attribute and a default value.
  • Second, include the world.launch file from the gazebo_ros package. The empty_world file includes a set of important definitions that are inherited by the world that we create. Using the world_name argument and the path to your .world file passed as the value to that argument, you will be able to launch your world in Gazebo.

Launch empty.world

$ cd /home/workspace/catkin_ws/
$ catkin_make
$ source devel/setup.bash
$ roslaunch my_robot world.launch

Empty Gazebo world with a sun shining from the top!

Empty Gazebo world with a sun shining from the top!

It does look a bit bland, but don't worry, there will soon be a different world for your robot to explore!

Task Description:

Follow these steps to set up the my_robot package

Task List:

Task Feedback:

Great job!